﻿using System;

namespace Having.Site.Attr
{
    /// <summary>
    /// 用户权限类型
    /// </summary>
    public class UserT
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public string appId { set; get; }
        /// <summary>
        /// 用户代表的类型
        /// </summary>
        public UserType apptype { set; get; }
        /// <summary>
        /// ip或者物理mac
        /// </summary>
        public string ipmac { set; get; }
        /// <summary>
        /// 环境变量
        /// </summary>
        public string brower { set; get; }
        /// <summary>
        /// 最后登录的时间（yyyyMMddHHmmss）
        /// </summary>
        public string dt { set; get; }
        /// <summary>
        /// 用户对应数据库表的token
        /// </summary>
        public string token { set; get; }
        /// <summary>
        /// 附加信息
        /// </summary>
        public string extend { set; get; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_appId">用户ID</param>
        /// <param name="_apptype">用户代表的类型</param>
        /// <param name="_brower">环境变量</param>
        /// <param name="_dt">最后登录的时间</param>
        /// <param name="_token">用户在数据库上的token</param>
        /// <param name="_ipmac">ip地址或者物理mac</param>
        /// <param name="_extend">附加信息</param>
        public UserT(string _appId = "", string _apptype = "", string _token = "", string _ipmac = "", string _brower = "", string _dt = "", string _extend = "")
        {
            this.appId = _appId;
            this.apptype = string.IsNullOrWhiteSpace(_apptype)? UserType.def:(UserType) Enum.Parse(typeof(UserType), _apptype);
            this.brower = _brower;
            this.ipmac = _ipmac;
            this.dt = _dt;
            this.token = _token;
            this.extend = _extend;
        }
    }

    /// <summary>
    /// 用户权限
    /// </summary>
    public enum UserType
    {
        /// <summary>
        /// 默认（为空）
        /// </summary>
        def=1,
        /// <summary>
        /// 用户
        /// </summary>
        user=2,
        /// <summary>
        /// 商家
        /// </summary>
        buss=4,
        /// <summary>
        /// 管理员
        /// </summary>
        sys=8,
        /// <summary>
        /// 特殊的（接口）
        /// </summary>
        peculiar = 16,
        /// <summary>
        /// appid（接口）
        /// </summary>
        appid =32
    }
}
